2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex9_repeatSeq.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
69 //******************************************************************************
70 
71 
72 void main (void)
73 {
74  volatile uint16_t i;
75  //ADC conversion result array
76  uint16_t ADC_Result[64];
77 
78  //Stop Watchdog Timer
79  WDT_A_hold(WDT_A_BASE);
80 
81  //Initializae the ADC10_A Module
82  /*
83  * Base Address for the ADC10_A Module
84  * Use internal ADC10_A bit as sample/hold signal to start conversion
85  * USE MODOSC 5MHZ Digital Oscillator as clock source
86  * Use default clock divider of 1
87  */
88  ADC10_A_init(ADC10_A_BASE,
89  ADC10_A_SAMPLEHOLDSOURCE_SC,
90  ADC10_A_CLOCKSOURCE_ADC10OSC,
91  ADC10_A_CLOCKDIVIDER_1);
92 
93  ADC10_A_enable(ADC10_A_BASE);
94 
95  /*
96  * Base Address for the ADC10_A Module
97  * Sample/hold for 16 clock cycles
98  * Enable Multiple Sampling
99  */
100  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
101  ADC10_A_CYCLEHOLD_16_CYCLES,
102  ADC10_A_MULTIPLESAMPLESENABLE);
103 
104  //Configure Memory Buffer
105  /*
106  * Base Address for the ADC10_A Module
107  * Use input A1
108  * Use positive reference of AVcc
109  * Use negative reference of AVss
110  */
111  ADC10_A_configureMemory(ADC10_A_BASE,
112  ADC10_A_INPUT_A1,
113  ADC10_A_VREFPOS_AVCC,
114  ADC10_A_VREFNEG_AVSS);
115 
116 
117  //Initialize and Setup DMA Channel 0
118  /*
119  * Configure DMA channel 0
120  * Configure channel for repeated single transfer
121  * DMA interrupt flag will be set after every 2 transfers
122  * Use DMA Trigger Source 24 (ADC10IFG)
123  * Tranfer Word-to-Word
124  * Trigger upon Rising Edge of Trigger Source
125  */
126  DMA_initParam param = {0};
127  param.channelSelect = DMA_CHANNEL_0;
128  param.transferModeSelect = DMA_TRANSFER_REPEATED_SINGLE;
129  param.transferSize = 2;
130  param.triggerSourceSelect = DMA_TRIGGERSOURCE_24;
131  param.transferUnitSelect = DMA_SIZE_SRCWORD_DSTWORD;
132  param.triggerTypeSelect = DMA_TRIGGER_RISINGEDGE;
133  DMA_init(&param);
134  /*
135  * Base Address of the DMA Module
136  * Configure DMA channel 0
137  * Use ADC10_A Memory Buffer as source
138  * Increment destination address after every transfer
139  */
140  DMA_setSrcAddress(DMA_CHANNEL_0,
141  ADC10_A_getMemoryAddressForDMA(ADC10_A_BASE),
142  DMA_DIRECTION_UNCHANGED);
143 
144  //Enable DMA channel 0 interrupt
145  DMA_clearInterrupt(DMA_CHANNEL_0);
146  DMA_enableInterrupt(DMA_CHANNEL_0);
147 
148  //Enable transfers on DMA channel 0
149  DMA_enableTransfers(DMA_CHANNEL_0);
150 
151  while (1)
152  {
153  for (i = 0; i < 32; i++)
154  {
155  /*
156  * Base Address of the DMA Module
157  * Configure DMA channel 0
158  * Use ADC_Result[i*2] as destination
159  * Increment destination address after every transfer
160  */
161  DMA_setDstAddress(DMA_CHANNEL_0,
162  (uint32_t)(uintptr_t)&ADC_Result[i * 2],
163  DMA_DIRECTION_INCREMENT);
164 
165  //Wait if ADC10_A core is active
166  while (ADC10_A_isBusy(ADC10_A_BASE)) ;
167 
168  //Enable and Start the conversion
169  //in Repeated Sequence of Channels Conversion Mode
170  ADC10_A_startConversion(ADC10_A_BASE,
171  ADC10_A_REPEATED_SEQOFCHANNELS);
172 
173  //LPM0, ADC10_A_ISR will force exit
174  __bis_SR_register(CPUOFF + GIE);
175  }
176 
177  //Delay between sequence convs
178  __delay_cycles(5000);
179  //BREAKPOINT; check ADC_Result
180  __no_operation();
181  }
182 }
183 
184 // DMA interrupt service routine
185 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
186 __interrupt
187 #elif defined(__GNUC__)
188 __attribute__((interrupt(DMA_VECTOR)))
189 #endif
190 void DMA0_ISR (void) {
191  switch (__even_in_range(DMAIV,16)){
192  case 0: break; //No interrupt
193  case 2: //DMA0IFG
194  //Sequence of Channels Conversion Complete
195  //Disable Conversion without pre-empting any conversions taking place.
196  ADC10_A_disableConversions(ADC10_A_BASE, ADC10_A_PREEMPTCONVERSION);
197  //exit LPM
199  break;
200  case 4: break; //DMA1IFG
201  case 6: break; //DMA2IFG
202  default: break;
203  }
204 }
205 
MPU_initThreeSegmentsParam param
void main(void)
void DMA0_ISR(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
__delay_cycles(500000)